package com.jy.modules.cims.contract.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jy.modules.cims.component.common.service.TCMmAgreementService;
import com.jy.modules.cims.component.common.service.TCMmContractService;
import com.jy.modules.cims.component.common.service.TCMmCooperorgService;
import com.jy.modules.cims.contract.service.ContractService;
import com.jy.modules.cims.data.common.dto.TCMmAgreementDTO;
import com.jy.modules.cims.data.common.dto.TCMmContractDTO;
import com.jy.modules.cims.data.common.dto.TCMmCooperorgDTO;
import com.jy.platform.core.message.DataMsg;

/**
 * 合约相关处理控制层
 */
@Controller
@Scope("prototype")
@RequestMapping("/contract")
public class ContactController {

    /**
     * 合约相关处理控制层
     */
    public ContactController() {
    }

    /**
     * 合约处理服务
     */
    public ContractService contractService;
    
    /**
     * 考虑开发进度，下面三个引用的服务先直接引用平台生成的服务，后续再调整至ContractService里
     * 合作机构处理服务，
     */
    @Autowired
    @Qualifier("com.jy.modules.cims.component.common.service.TCMmCooperorgService")
    private TCMmCooperorgService cooperorgService;
    
    /**
     * 协议处理服务
     */
    @Autowired
    @Qualifier("com.jy.modules.cims.component.common.service.TCMmAgreementService")
    private TCMmAgreementService agreementService;
    
    /**
     * 合约处理服务
     */
    @Autowired
    @Qualifier("com.jy.modules.cims.component.common.service.TCMmContractService")
    private TCMmContractService tcmmContractService;

    /**
     * 合作机构查询列表
     * @param request 
     * @param response 
     * @return
     */
    @RequestMapping(value = "/getCooperOrgList")
    @ResponseBody
    public DataMsg getCooperOrgList(HttpServletRequest request, TCMmCooperorgDTO dto, @ModelAttribute DataMsg dataMsg)  throws Exception {
    	Map<String, Object> searchParams = new HashMap<String, Object>();
    	searchParams.put("dto", dto);
        List<TCMmCooperorgDTO> list = cooperorgService.searchTCMmCooperorg(searchParams);
        dataMsg.setData(list);
        return dataMsg;
    }

    /**
     * 协议查询列表
     * @param request 
     * @param response 
     * @return
     */
    @RequestMapping(value = "/getAgreementList")
    @ResponseBody
    public DataMsg getAgreementList(HttpServletRequest request, TCMmAgreementDTO dto, @ModelAttribute DataMsg dataMsg)  throws Exception {
    	Map<String, Object> searchParams = new HashMap<String, Object>();
    	searchParams.put("dto", dto);
        List<TCMmAgreementDTO> list = agreementService.searchTCMmAgreement(searchParams);
        dataMsg.setData(list);
        return dataMsg;
    }

    /**
     * 合约查询列表
     * @param request 
     * @param response 
     * @return
     */
    @RequestMapping(value = "/getContractList")
    @ResponseBody
    public DataMsg getContractList(HttpServletRequest request, TCMmContractDTO dto, @ModelAttribute DataMsg dataMsg)  throws Exception {
    	Map<String, Object> searchParams = new HashMap<String, Object>();
    	searchParams.put("dto", dto);
        List<TCMmContractDTO> list = tcmmContractService.searchTCMmContract(searchParams);
        dataMsg.setData(list);
        return dataMsg;
    }

    /**
     * 获取合约综合信息
     * @param request 
     * @param response 
     * @return
     */
    public DataMsg getContractAllInfo(HttpServletRequest request, HttpServletResponse response) {
        // TODO implement here
        return null;
    }

}